package org.example.library;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import org.example.reservas_mesas.*;

public class CustomSimpleAdapter extends SimpleAdapter {

    private ArrayList<HashMap<String, String>> results;
    private String from[];
    private int to[];
    private Context MyContext;
    private ViewBinder binder;
    		
    public CustomSimpleAdapter(Context context, ArrayList<HashMap<String, String>> data, int resource, String[] from, int[] to)
    {
        super(context, data, resource, from, to);
        this.MyContext = context;
        this.results = data;
        this.to = to;
        this.from = from;
    }
	
	@Override
    public View getView(int position, View view, ViewGroup parent)
    {
    	View row = super.getView(position, view, parent);
    	int limite = to.length;
    	String[] paramBoton;
    	
        if (row == null) {
            LayoutInflater vi = (LayoutInflater)MyContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = vi.inflate(R.layout.row, null);
        }
    	
        for(int i = 0; i < limite; i++)
        {
        	if(row.findViewById(to[i]) instanceof Button)
        	{
        		((Button)row.findViewById(to[i])).setTag((((HashMap<String, String>) super.getItem(position)).get(from[i])));      		
        		
        	}
        }
    	return row;
    }
	
	

}
